/*
 * @lc app=leetcode.cn id=119 lang=csharp
 *
 * [119] 杨辉三角 II
 */

// @lc code=start
public class Solution {
    public IList<int> GetRow(int rowIndex) {
        List<IList<int>> ans = new List<IList<int>>();
        ans.Add(new List<int>(){1});
        for (int i = 1; i < rowIndex + 1; i++)
        {
            var lastRow = ans[i - 1];
            List<int> newRow = new List<int>();
            
            for (int col = 0; col <= i; col++)
            {
                int left = col - 1 >= 0 ? lastRow[col - 1] : 0;
                int right = col < lastRow.Count ? lastRow[col] : 0;
                newRow.Add(left + right);
            }
            ans.Add(newRow);
        }
        return ans[rowIndex];
    }
}
// @lc code=end

